Change cargo to explicitly set curl proxy settings only when necessary
authorcalc0000 <ewf>
Wed, 18 Feb 2015 01:39:27 +0000 (20:39 -0500)
committercalc0000 <ewf>
Thu, 19 Feb 2015 04:49:11 +0000 (23:49 -0500)
(when it is specified in either the cargo config or the git config).
Otherwise, use curl's logic to pick a proxy (or not).

src/bin/cargo.rs
src/cargo/ops/mod.rs
src/cargo/ops/registry.rs

index 53c904d341057296022fc7a5b11e6b38550c01dc..b69459da71e750fd2fb5de67d4ec57ed3b3a5761 100644 (file)
@@ -255,8 +255,8 @@ fn init_git_transports(config: &Config) {
     // Only use a custom transport if a proxy is configured, right now libgit2
     // doesn't support proxies and we have to use a custom transport in this
     // case. The custom transport, however, is not as well battle-tested.
-    match cargo::ops::http_proxy(config) {
-        Ok(Some(..)) => {}
+    match cargo::ops::http_proxy_exists(config) {
+        Ok(true) => {}
         _ => return
     }
 
index b170a050ff90b59932d3092e2b3174da951e8bca..6b7341527e53df9dfefe3a92501340a86c1931fd 100644 (file)
@@ -17,7 +17,7 @@ pub use self::lockfile::{write_lockfile, write_pkg_lockfile};
 pub use self::cargo_test::{run_tests, run_benches, TestOptions};
 pub use self::cargo_package::package;
 pub use self::registry::{publish, registry_configuration, RegistryConfig};
-pub use self::registry::{registry_login, search, http_proxy, http_handle};
+pub use self::registry::{registry_login, search, http_proxy_exists, http_handle};
 pub use self::registry::{modify_owners, yank, OwnersOptions};
 pub use self::cargo_fetch::{fetch};
 pub use self::cargo_pkgid::pkgid;
index 59754f20ba7b5bcb3d662c92a980d70dbf241ba6..7ef7fe354f827a691ab002b9c23930b6e2d02c6d 100644 (file)
@@ -173,11 +173,11 @@ pub fn http_handle(config: &Config) -> CargoResult<http::Handle> {
     Ok(handle)
 }
 
-/// Find a globally configured HTTP proxy if one is available.
+/// Find an explicit HTTP proxy if one is available.
 ///
-/// Favor cargo's `http.proxy`, then git's `http.proxy`, then finally a
-/// HTTP_PROXY env var.
-pub fn http_proxy(config: &Config) -> CargoResult<Option<String>> {
+/// Favor cargo's `http.proxy`, then git's `http.proxy`. Proxies specified
+/// via environment variables are picked up by libcurl.
+fn http_proxy(config: &Config) -> CargoResult<Option<String>> {
     match try!(config.get_string("http.proxy")) {
         Some((s, _)) => return Ok(Some(s)),
         None => {}
@@ -191,7 +191,26 @@ pub fn http_proxy(config: &Config) -> CargoResult<Option<String>> {
         }
         Err(..) => {}
     }
-    Ok(env::var("HTTP_PROXY").ok())
+    Ok(None)
+}
+
+/// Determine if an http proxy exists.
+///
+/// Checks the following for existence, in order:
+///
+/// * cargo's `http.proxy`
+/// * git's `http.proxy`
+/// * http_proxy env var
+/// * HTTP_PROXY env var
+/// * https_proxy env var
+/// * HTTPS_PROXY env var
+pub fn http_proxy_exists(config: &Config) -> CargoResult<bool> {
+    if try!(http_proxy(config)).is_some() {
+        Ok(true)
+    } else {
+        Ok(["http_proxy", "HTTP_PROXY",
+           "https_proxy", "HTTPS_PROXY"].iter().any(|v| env::var(v).is_ok()))
+    }
 }
 
 pub fn http_timeout(config: &Config) -> CargoResult<Option<i64>> {